#ifndef THINK_THINK_VIEW_H
#define THINK_THINK_VIEW_H

static char* think_view =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | ThinkPHP [ WE CAN DO IT JUST THINK ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: liu21st <liu21st@gmail.com>\n"
	"// +----------------------------------------------------------------------\n"
	"\n"
	"namespace think;\n"
	"\n"
	"class View\n"
	"{\n"
	"    // 视图实例\n"
	"    protected static $instance;\n"
	"    // 模板引擎实例\n"
	"    public $engine;\n"
	"    // 模板变量\n"
	"    protected $data = [];\n"
	"    // 用于静态赋值的模板变量\n"
	"    protected static $var = [];\n"
	"    // 视图输出替换\n"
	"    protected $replace = [];\n"
	"\n"
	"    /**\n"
	"     * 构造函数\n"
	"     * @access public\n"
	"     * @param array $engine  模板引擎参数\n"
	"     * @param array $replace  字符串替换参数\n"
	"     */\n"
	"    public function __construct($engine = [], $replace = [])\n"
	"    {\n"
	"        // 初始化模板引擎\n"
	"        $this->engine($engine);\n"
	"        // 基础替换字符串\n"
	"        $request = Request::instance();\n"
	"        $base    = $request->root();\n"
	"        $root    = strpos($base, \'.\') ? ltrim(dirname($base), DS) : $base;\n"
	"        if (\'\' != $root) {\n"
	"            $root = \'/\' . ltrim($root, \'/\');\n"
	"        }\n"
	"        $baseReplace = [\n"
	"            \'__ROOT__\'   => $root,\n"
	"            \'__URL__\'    => $base . \'/\' . $request->module() . \'/\' . Loader::parseName($request->controller()),\n"
	"            \'__STATIC__\' => $root . \'/static\',\n"
	"            \'__CSS__\'    => $root . \'/static/css\',\n"
	"            \'__JS__\'     => $root . \'/static/js\',\n"
	"        ];\n"
	"        $this->replace = array_merge($baseReplace, (array) $replace);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 初始化视图\n"
	"     * @access public\n"
	"     * @param array $engine  模板引擎参数\n"
	"     * @param array $replace  字符串替换参数\n"
	"     * @return object\n"
	"     */\n"
	"    public static function instance($engine = [], $replace = [])\n"
	"    {\n"
	"        if (is_null(self::$instance)) {\n"
	"            self::$instance = new self($engine, $replace);\n"
	"        }\n"
	"        return self::$instance;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 模板变量静态赋值\n"
	"     * @access public\n"
	"     * @param mixed $name  变量名\n"
	"     * @param mixed $value 变量值\n"
	"     * @return void\n"
	"     */\n"
	"    public static function share($name, $value = \'\')\n"
	"    {\n"
	"        if (is_array($name)) {\n"
	"            self::$var = array_merge(self::$var, $name);\n"
	"        } else {\n"
	"            self::$var[$name] = $value;\n"
	"        }\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 模板变量赋值\n"
	"     * @access public\n"
	"     * @param mixed $name  变量名\n"
	"     * @param mixed $value 变量值\n"
	"     * @return $this\n"
	"     */\n"
	"    public function assign($name, $value = \'\')\n"
	"    {\n"
	"        if (is_array($name)) {\n"
	"            $this->data = array_merge($this->data, $name);\n"
	"        } else {\n"
	"            $this->data[$name] = $value;\n"
	"        }\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 设置当前模板解析的引擎\n"
	"     * @access public\n"
	"     * @param array|string $options 引擎参数\n"
	"     * @return $this\n"
	"     */\n"
	"    public function engine($options = [])\n"
	"    {\n"
	"        if (is_string($options)) {\n"
	"            $type    = $options;\n"
	"            $options = [];\n"
	"        } else {\n"
	"            $type = !empty($options[\'type\']) ? $options[\'type\'] : \'Think\';\n"
	"        }\n"
	"\n"
	"        $class = false !== strpos($type, \'\\\\\') ? $type : \'\\\\think\\\\view\\\\driver\\\\\' . ucfirst($type);\n"
	"        if (isset($options[\'type\'])) {\n"
	"            unset($options[\'type\']);\n"
	"        }\n"
	"        $this->engine = new $class($options);\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 配置模板引擎\n"
	"     * @access private\n"
	"     * @param string|array  $name 参数名\n"
	"     * @param mixed         $value 参数值\n"
	"     * @return $this\n"
	"     */\n"
	"    public function config($name, $value = null)\n"
	"    {\n"
	"        $this->engine->config($name, $value);\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 解析和获取模板内容 用于输出\n"
	"     * @param string    $template 模板文件名或者内容\n"
	"     * @param array     $vars     模板输出变量\n"
	"     * @param array     $replace 替换内容\n"
	"     * @param array     $config     模板参数\n"
	"     * @param bool      $renderContent     是否渲染内容\n"
	"     * @return string\n"
	"     * @throws Exception\n"
	"     */\n"
	"    public function fetch($template = \'\', $vars = [], $replace = [], $config = [], $renderContent = false)\n"
	"    {\n"
	"        // 模板变量\n"
	"        $vars = array_merge(self::$var, $this->data, $vars);\n"
	"\n"
	"        // 页面缓存\n"
	"        ob_start();\n"
	"        ob_implicit_flush(0);\n"
	"\n"
	"        // 渲染输出\n"
	"        try {\n"
	"            $method = $renderContent ? \'display\' : \'fetch\';\n"
	"            // 允许用户自定义模板的字符串替换\n"
	"            $replace = array_merge($this->replace, $replace, (array) $this->engine->config(\'tpl_replace_string\'));\n"
	"            $this->engine->config(\'tpl_replace_string\', $replace);\n"
	"            $this->engine->$method($template, $vars, $config);\n"
	"        } catch (\\Exception $e) {\n"
	"            ob_end_clean();\n"
	"            throw $e;\n"
	"        }\n"
	"\n"
	"        // 获取并清空缓存\n"
	"        $content = ob_get_clean();\n"
	"        // 内容过滤标签\n"
	"        Hook::listen(\'view_filter\', $content);\n"
	"        return $content;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 视图内容替换\n"
	"     * @access public\n"
	"     * @param string|array  $content 被替换内容（支持批量替换）\n"
	"     * @param string        $replace    替换内容\n"
	"     * @return $this\n"
	"     */\n"
	"    public function replace($content, $replace = \'\')\n"
	"    {\n"
	"        if (is_array($content)) {\n"
	"            $this->replace = array_merge($this->replace, $content);\n"
	"        } else {\n"
	"            $this->replace[$content] = $replace;\n"
	"        }\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 渲染内容输出\n"
	"     * @access public\n"
	"     * @param string $content 内容\n"
	"     * @param array  $vars    模板输出变量\n"
	"     * @param array  $replace 替换内容\n"
	"     * @param array  $config     模板参数\n"
	"     * @return mixed\n"
	"     */\n"
	"    public function display($content, $vars = [], $replace = [], $config = [])\n"
	"    {\n"
	"        return $this->fetch($content, $vars, $replace, $config, true);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 模板变量赋值\n"
	"     * @access public\n"
	"     * @param string    $name  变量名\n"
	"     * @param mixed     $value 变量值\n"
	"     */\n"
	"    public function __set($name, $value)\n"
	"    {\n"
	"        $this->data[$name] = $value;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 取得模板显示变量的值\n"
	"     * @access protected\n"
	"     * @param string $name 模板变量\n"
	"     * @return mixed\n"
	"     */\n"
	"    public function __get($name)\n"
	"    {\n"
	"        return $this->data[$name];\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 检测模板变量是否设置\n"
	"     * @access public\n"
	"     * @param string $name 模板变量名\n"
	"     * @return bool\n"
	"     */\n"
	"    public function __isset($name)\n"
	"    {\n"
	"        return isset($this->data[$name]);\n"
	"    }\n"
	"}\n"
	"\n"
;
#endif